package com.dongdong.controller;


import com.dongdong.service.ContentService;
import com.dongdong.utils.PageBean;
import com.dongdong.utils.PageResult;
import com.dongdong.utils.Result;
import com.dongdong.vo.ContentCategoryVO;
import com.dongdong.vo.ContentVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/content")
public class ContentController {

    @Autowired
    private ContentService contentService;

    @PostMapping("/getContentCategoryPage")
    public Result getContentCategoryPage(@RequestBody PageBean<ContentCategoryVO> pageBean){

        PageResult<ContentCategoryVO> pageResult = contentService.getContentCategoryPage(pageBean);
        return Result.OK().setData(pageResult);
    }


    @PostMapping("/getContentPage")
    public Result getContentPage(@RequestBody PageBean<ContentVO> pageBean){

        PageResult<ContentVO> pageResult = contentService.getContentPage(pageBean);
        return Result.OK().setData(pageResult);
    }

    /**
     * 根据分类id查询
     * @param id
     * @return
     */
    @GetMapping("/getCategoryById")
    public Result getCategoryById(@RequestParam Long id){
        ContentCategoryVO categoryVO = contentService.getCategoryById(id);
        return Result.OK().setData(categoryVO);
    }

    /**
     * 修改
     * @param categoryVO
     * @return
     */
    @PutMapping("/updateCategory")
    public Result updateCategory(@RequestBody ContentCategoryVO categoryVO){
        contentService.updateCategory(categoryVO);
        return Result.OK();
    }

    /**
     * 添加
     * @param categoryVO
     * @return
     */
    @PostMapping("/addCategory")
    public Result addCategory(@RequestBody ContentCategoryVO categoryVO){
        contentService.addCategory(categoryVO);
        return Result.OK();
    }

    /**
     * 根据id删除分类
     * @param id
     * @return
     */
    @DeleteMapping("/deleteCategoryById")
    public Result deleteCategoryById(@RequestParam Long id){
        return contentService.deleteCategoryById(id);
    }

    /**
     * 获取所有分类
     * @return
     */
    @GetMapping("/getCategoryList")
    public Result getCategoryList(){
        List<ContentCategoryVO> categoryVOS = contentService.getCategoryList();
        return Result.OK().setData(categoryVOS);
    }




}
